package com.frank.libandroid;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

public class BaseVMActivity<V extends ViewDataBinding, VM extends BaseViewModel> extends BaseActivity<V> {
    protected VM mViewModel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Class<VM> vmClass = (Class<VM>) ReflectUtil.getGeneric(this, 1);
        mViewModel = new ViewModelProvider(this).get(vmClass);
    }

    protected <T> void watch(Key<T> key, Observer<T> observer) {
        LiveDataBus.with(key).observe(this, observer);
    }
}
